package com.nkym.wypan.response;/*
 * @ClassName BaseResponse
 * @Desc TODO
 * @Author 19637
 * @Date 2023/6/5 11:27
 * @Version 1.0
 */

import com.nkym.wypan.enums.ResponseStatus;
import lombok.Data;

@Data
public class BaseResponse<T> {
    private T data;
    private boolean success = true;
    private Integer code;
    private String message;

    private BaseResponse(T data) {
        this.data = data;
    }

    private BaseResponse(T data, Integer code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public BaseResponse(T data, boolean success, Integer code, String message) {
        this.data = data;
        this.success = success;
        this.code = code;
        this.message = message;
    }

    private BaseResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> BaseResponse<T> ok(T data) {
        return new BaseResponse<>(data, ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getDesc());
    }

    public static <T> BaseResponse<T> ok() {
        return new BaseResponse<>(null, ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getDesc());
    }

    public static <T> BaseResponse<T> ok(ResponseStatus responseStatus) {
        return new BaseResponse<>(null, responseStatus.getCode(), responseStatus.getDesc());
    }
    public static <T> BaseResponse<T> fail(ResponseStatus responseStatus) {
        return new BaseResponse<>(null, false,responseStatus.getCode(), responseStatus.getDesc());
    }
    public static <T> BaseResponse<T> okPutMessage(String message) {
        return new BaseResponse<>(null, ResponseStatus.SUCCESS.getCode(), message);
    }

    public static <T> BaseResponse<T> fail(T data) {
        return new BaseResponse<>(data, ResponseStatus.FAIL.getCode(), ResponseStatus.FAIL.getDesc());
    }

    public static <T> BaseResponse<T> fail() {
        return new BaseResponse<>(null, false, ResponseStatus.FAIL.getCode(), ResponseStatus.FAIL.getDesc());
    }

    public static <T> BaseResponse<T> fail(Integer code, String message) {
        return new BaseResponse<>(null, false, code, message);
    }

    public static <T> BaseResponse<T> failPutMessage(String message) {
        return new BaseResponse<>(null, false, ResponseStatus.FAIL.getCode(), message);
    }
}
